import random
x1=random.randint(0,10)#乌龟的初始位置
y1=random.randint(0,10)
print('小龟初始位置在（{0},{1}）'.format(x1,y1))
power = 100     # 初始体力
count = 0   # 用于跳出

# 小鱼的初始位置
j1 = random.randint(0, 10)
k1 = random.randint(0, 10)
j2 = random.randint(0, 10)
k2 = random.randint(0, 10)
j3 = random.randint(0, 10)
k3 = random.randint(0, 10)
j4 = random.randint(0, 10)
k4 = random.randint(0, 10)
j5 = random.randint(0, 10)
k5 = random.randint(0, 10)
j6 = random.randint(0, 10)
k6 = random.randint(0, 10)
j7 = random.randint(0, 10)
k7 = random.randint(0, 10)
j8 = random.randint(0, 10)
k8 = random.randint(0, 10)
j9 = random.randint(0, 10)
k9 = random.randint(0, 10)
j10 = random.randint(0, 10)
k10 = random.randint(0, 10)
# 将小鱼的位置做成字典存储，当与小龟重复则删掉
fish = {'F1':(j1,k1),'F2':(j2,k2),'F3':(j3,k3),'F4':(j4,k4),'F5':(j5,k5),'F6':(j6,k6),'F7':(j7,k7),'F8':(j8,k8),'F9':(j9,k9),'F10':(j10,k10)}


while count == 0:

    class Wugui:
        """小乌龟的类"""
        # 移动(距离方向（随机）)
        x1 = random.randint(-2, 2)  # x方向移动距离
        y1 = random.randint(-2, 2)  # y方向移动距离

        def mov(self, x, y,power):
            # 开始动了
            x += self.x1
            y += self.y1
            power -= 1  # 移动一次体力减1
            return x,y,power

        def peng(self,x,y):
            # 判断是否碰壁
            if x < 0:
                x = 0 - x
            if x > 10:
                x = 10 - x % 10
            if y < 0:
                y = 0 - y
            if y > 10:
                y = 10 - y % 10
            return x,y

    class Yu:
        """小鱼的类"""

        def mov(self,j,k):
            # 移动(方向、距离)
            j1 = random.randint(-1, 1)  # x方向移动距离
            k1 = random.randint(-1, 1)  # y方向移动距离
            # 开始动了
            j += j1
            k += k1
            return j,k

        def peng(self,j,k):
            # 判断是否碰壁走反向没出来
            if j < 0:
                j = 0-j
            if j > 10:
                j = 10-j%10
            if k < 0:
                k = 0-k
            if k > 10:
                k = 10-k%10
            return j,k

    gui = Wugui()
    (x1,y1,power) = gui.mov(x1,y1,power)    #龟动
    (x1,y1) = gui.peng(x1,y1)   #测龟碰
    print("小龟移动到了（{0},{1}）".format(x1,y1))
    print('体力:{0}'.format(power))

    def fmp(name):
        """输入字典中鱼名；
           根据对应旧位置输出新位置"""
        (j,k) = fish[name] # 获取旧鱼位置
        n = Yu()
        (j,k) = n.mov(j,k)#移动
        return n.peng(j,k)#碰壁

    if 'F1' in fish:
        fish['F1'] = fmp('F1')   # 如果小鱼没有移动的话继续让他动起来
    if 'F2' in fish:
        fish['F2'] = fmp('F2')
    if 'F3' in fish:
        fish['F3'] = fmp('F3')
    if 'F4' in fish:
        fish['F4'] = fmp('F4')
    if 'F5' in fish:
        fish['F5'] = fmp('F5')
    if 'F6' in fish:
        fish['F6'] = fmp('F6')
    if 'F7' in fish:
        fish['F7'] = fmp('F7')
    if 'F8' in fish:
        fish['F8'] = fmp('F8')
    if 'F9' in fish:
        fish['F9'] = fmp('F9')
    if 'F10' in fish:
        fish['F10'] = fmp('F10')

    print('小鱼位置{0}'.format(fish))

    # 判断小鱼是否被吃（根据值（位置）找到键（鱼名）并把重复的删除）
    if (x1,y1) in fish.values():
        """小鱼被吃掉（删掉小鱼对象），体力增加20"""
        F = []
        for a in range(0, len(fish)):
            if list(fish.values())[a] == (x1,y1):
                F.append((list(fish.keys())[a]))    # 找到重复小鱼的键放在一起
                power += 20  # 体力加20
                if (power>=100):
                    power=100
        # 删掉与乌龟同一位置的小鱼
        for del_fish in F:
            print('小鱼{0}被吃掉啦！乌龟在{1}'.format(del_fish,(x1,y1)))
            del fish[del_fish]       # 删掉位置重复的小鱼

    # 结束跳出
    if power == 0:
        """判断结束条件"""
        print("小乌龟被饿死啦")
        count = 1
    if len(fish) == 0:
        print('小鱼被吃光啦！')
        count = 1
